package com.kelaite.procurement.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity(name = "t_vendor")
public class TVendor extends TBaseEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Long id;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "client_id")
	private TCompany tClient;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "supplier_id")
	private TCompany tSupplier;

	@Column(name = "status")
	private short status; // 1.待审核、2.潜在供应商、3.有效供应商、4.黑名单

	@Column(name = "vendor_no", nullable = false, length = 30)
	private String vendorNo;

	@Column(name = "vendor_name", nullable = false, length = 30)
	private String vendorName;

	@Column(name = "status_from_date")
	private Date statusFromDate;

	@Column(name = "status_to_date")
	private Date statusToDate;

	@Column(name = "grade", nullable = false, length = 2)
	private String grade;

	@Column(name = "grade_from_date")
	private Date gradeFromDate;

	@Column(name = "grade_to_date")
	private Date gradeToDate;

	@Column(name = "users_limit_num", length = 4)
	private int usersLimitNum;

	@Column(name = "gmt_create_time")
	private Date gmtCreateTime;

	@Column(name = "gmt_update_time")
	private Date gmtUpdateTime;

	@Column(name = "created_by", length = 30)
	private String createdBy;

	@Column(name = "updated_by", length = 30)
	private String updatedBy;

	@Column(name = "is_delete")
	private boolean isDelete;
	
	@OneToMany(mappedBy = "tVendor", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy(value = "id ASC")
	@JsonIgnore
	private List<TVendorHistory> tVendorHistory = new ArrayList<TVendorHistory>();
	
	@OneToMany(mappedBy = "tVendor", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@OrderBy(value = "id ASC")
	@JsonIgnore
	private List<TPurchaseOrder> tPurchaseOrder = new ArrayList<TPurchaseOrder>();
	
	public List<TPurchaseOrder> gettPurchaseOrder() {
		return tPurchaseOrder;
	}

	public void settPurchaseOrder(List<TPurchaseOrder> tPurchaseOrder) {
		this.tPurchaseOrder = tPurchaseOrder;
	}

	public List<TVendorHistory> gettVendorHistory() {
		return tVendorHistory;
	}

	public void settVendorHistory(List<TVendorHistory> tVendorHistory) {
		this.tVendorHistory = tVendorHistory;
	}

	public TVendor() {

	}

	public Long getId() {

		return id;
	}

	public void setId(Long id) {

		this.id = id;
	}

	public TCompany gettClient() {

		return tClient;
	}

	public void settClient(TCompany tClient) {

		this.tClient = tClient;
	}

	public TCompany gettSupplier() {

		return tSupplier;
	}

	public void settSupplier(TCompany tSupplier) {

		this.tSupplier = tSupplier;
	}

	public short getStatus() {

		return status;
	}

	public void setStatus(short status) {

		this.status = status;
	}

	public String getVendorNo() {

		return vendorNo;
	}

	public void setVendorNo(String vendorNo) {

		this.vendorNo = vendorNo;
	}

	public String getVendorName() {

		return vendorName;
	}

	public void setVendorName(String vendorName) {

		this.vendorName = vendorName;
	}

	public Date getStatusFromDate() {

		return statusFromDate;
	}

	public void setStatusFromDate(Date statusFromDate) {

		this.statusFromDate = statusFromDate;
	}

	public Date getStatusToDate() {

		return statusToDate;
	}

	public void setStatusToDate(Date statusToDate) {

		this.statusToDate = statusToDate;
	}

	public String getGrade() {

		return grade;
	}

	public void setGrade(String grade) {

		this.grade = grade;
	}

	public Date getGradeFromDate() {

		return gradeFromDate;
	}

	public void setGradeFromDate(Date gradeFromDate) {

		this.gradeFromDate = gradeFromDate;
	}

	public Date getGradeToDate() {

		return gradeToDate;
	}

	public void setGradeToDate(Date gradeToDate) {

		this.gradeToDate = gradeToDate;
	}

	public int getUsersLimitNum() {

		return usersLimitNum;
	}

	public void setUsersLimitNum(int usersLimitNum) {

		this.usersLimitNum = usersLimitNum;
	}

	public Date getGmtCreateTime() {

		return gmtCreateTime;
	}

	public void setGmtCreateTime(Date gmtCreateTime) {

		this.gmtCreateTime = gmtCreateTime;
	}

	public Date getGmtUpdateTime() {

		return gmtUpdateTime;
	}

	public void setGmtUpdateTime(Date gmtUpdateTime) {

		this.gmtUpdateTime = gmtUpdateTime;
	}

	public String getCreatedBy() {

		return createdBy;
	}

	public void setCreatedBy(String createdBy) {

		this.createdBy = createdBy;
	}

	public String getUpdatedBy() {

		return updatedBy;
	}

	public void setUpdatedBy(String updatedBy) {

		this.updatedBy = updatedBy;
	}

	public boolean isDelete() {

		return isDelete;
	}

	public void setDelete(boolean isDelete) {

		this.isDelete = isDelete;
	}

}
